#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <listitem.h>
#include <QDebug>

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::on_addStr_clicked()
{
    //在列表中添加字符串
    ui->listWidget->addItem("列表测试");
}

void MainWindow::on_addWidget_clicked()
{
    //添加窗口
    //创建列表项窗口--自定义
    listitem *winitem = new listitem();
    QListWidgetItem *item = new QListWidgetItem();

    //把列表项item尺寸位置与窗口一致
    item->setSizeHint(winitem->sizeHint());

    ui->listWidget->addItem(item);
    ui->listWidget->setItemWidget(item,winitem);

}

void MainWindow::on_deleteWidget_clicked()
{
    //获取当前选中行
    int row = ui->listWidget->currentRow();
    QListWidgetItem *item = ui->listWidget->takeItem(row);
    delete item;

}

void MainWindow::on_listWidget_itemDoubleClicked(QListWidgetItem *item)
{
    if(item->text()==""){
        //通过列表项获取窗口
        listitem *winitem = (listitem*)ui->listWidget->itemWidget(item);
    }else
        qDebug()<<item->text();
}
